const env_ios = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)

export function isIOS() {
  return env_ios
}

export function isIOSX() {
  return (
    env_ios &&
    window.screen.height >= 812 &&
    window.devicePixelRatio &&
    window.devicePixelRatio >= 2
  )
}

const env_android = !!navigator.userAgent.match(/android/i)

/**
 * @description 判断是否为安卓
 * @export
 * @returns {boolean}
 */
export function isAndroid() {
  return env_android
}

const env_app = !!navigator.userAgent.match(/yyngov\/(\d+(\.\d+)+)/i)

/**
 * @description 判断是否为app
 * @export
 * @returns {boolean}
 */
export function isApp() {
  return env_app
}

const supportWebP = (() => {
  try {
    return (
      document
        .createElement('canvas')
        .toDataURL('image/webp')
        .indexOf('data:image/webp') === 0
    )
  } catch (e) {
    // todo
  }
  return false
})()

export function isWebpSupported() {
  return supportWebP
}

export function isHTTPLink(link) {
  return !!(link && link.match(/^https?:/i))
}

export function isAppLink(link) {
  return !!(link && link.match(/^yyn:/i))
}
